/* 
 *  porting from adb 
 */

#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>

#define ADB_TRACING 1


pthread_mutex_t D_lock;


#  define  D(...)								\
	do {										\
		if (ADB_TRACING) {						\
			int save_errno = errno;				\
			pthread_mutex_lock(&D_lock);			\
			time_t __lt = time(NULL);			\
			char *__t = ctime(&__lt);			\
			__t[strlen(__t)-1] = '\0';			\
			fprintf(stderr, "%s  ", __t);		\
			fprintf(stderr, "%s::%s():",		\
					__FILE__, __FUNCTION__);	\
			errno = save_errno;					\
			fprintf(stderr, __VA_ARGS__ );		\
			fflush(stderr);						\
			pthread_mutex_unlock(&D_lock);			\
			errno = save_errno;					\
		}										\
	} while (0)

int main()
{
	D("test\n");
	return 0;
}
